import be.arteveldehogeschool.valueObjects.UserVO;

import mx.collections.ArrayList;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;

[Bindable]
public var userslist:ArrayList;

public function callGetUser():void
{
	alert("Gebruiker inloggen …");
	userService.setCredentials('olivier.parent@arteveldehs.be','12345678');
	//userService.setRemoteCredentials('olivier.parent@arteveldehs.be','12345678');
	userService.getUser();
}

public function returnGetUser(event:ResultEvent):void
{
	alert("Ontvangen gebruiker:");
	var user:UserVO = UserVO(event.result);
	alert(user.toString() + "\n");
}

public function callGetUsers():void
{
	alert("Gebruikers opvragen …");
	userService.getUsers();
}

public function returnGetUsers(event:ResultEvent):void
{
	alert("Ontvangen gebruikers:");
	var users:Array = event.result as Array;

	for each (var user:UserVO in users) {
		alert(user.toString());
	}
	alert("");
}

public function callGetUsersList():void
{
	alert("Gebruikerslijst opvragen …");
	userService.getUsersList();
}

public function returnGetUsersList(event:ResultEvent):void
{
	alert("Gebruikerslijst ontvangen.\n");
	var users:Array = event.result as Array;
	userslist = new ArrayList(users);	
}

public function returnError(event:FaultEvent):void
{
	alert(event.fault.faultString + " " + event.fault.faultCode + " " + event.fault.faultDetail);
}

private function alert(text:String):void
{
	taOutput.appendText(text + "\n");
}